using System;
using System.ComponentModel.Design;
using System.IO;
using System.Reflection;
using Microsoft.WowAddonStudio.FrameXml.Editor.Support;
using Microsoft.WowAddonStudio.FrameXml.Editor.Test.Mocks;
using Microsoft.WowAddonStudio.Services;
using Microsoft.WowAddonStudio.Tests.Common.Mocks;

using NUnit.Framework;

namespace Microsoft.WowAddonStudio.FrameXml.Editor.Test
{
	[TestFixture]
	public class ResourceFileLoaderFactoryTest
	{
		private IServiceContainer serviceContainer;

		#region SetUp

		[TestFixtureSetUp]
		public void TestFixtureSetUp()
		{
			serviceContainer = new SimpleTestServiceLocator();
		}

		[SetUp]
		public void SetUp()
		{

		}

		#endregion

		#region TearDown

		[TearDown]
		public void TearDown()
		{
			serviceContainer.RemoveService(typeof(IWowLocatorService));
		}

		#endregion

		#region Tests

		[Test(Description = "")]
		public void Test_CreateResourceFileLoaderDefault()
		{
			var resourceFileLoader = ResourceFileLoaderFactory.CreateResourceFileLoader();
			Assert.IsNotNull(resourceFileLoader);
		}

		[Test(Description = "")]
		[ExpectedException(typeof(ArgumentException), ExpectedMessage = "A required service 'WowLocatorService' is missing.")]
		public void Test_CreateResourceFileLoaderFailedWithArgumentException()
		{
			var resourceFileLoader = ResourceFileLoaderFactory.CreateResourceFileLoader(serviceContainer);
			Assert.IsNotNull(resourceFileLoader);
		}

		[Test(Description = "")]
		[ExpectedException(typeof(InvalidWowBasePathException), ExpectedMessage = "Invalid World of Warcraft base path.")]
		public void Test_CreateResourceFileLoaderFailedWithInvalidWowBasePath()
		{
			serviceContainer.AddService(typeof(IWowLocatorService), new MockWowLocatorService(@"C:\erteqrt\tret"));
			var resourceFileLoader = ResourceFileLoaderFactory.CreateResourceFileLoader(serviceContainer);
			Assert.IsNotNull(resourceFileLoader);
		}

		[Test(Description = "")]
		public void Test_CreateResourceFileLoader()
		{
			serviceContainer.AddService(typeof(IWowLocatorService),
				new MockWowLocatorService(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)));
			var resourceFileLoader = ResourceFileLoaderFactory.CreateResourceFileLoader(serviceContainer);
			Assert.IsNotNull(resourceFileLoader);
		}

		#endregion
	}
}